﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.WebUtils;
using SGT_ON;
using System.Web.Security;

public partial class EjecucionTareas : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void dsTareasLineaDeTiempo_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.Cancel = true;
        if (UsuariosDropDownlist.SelectedIndex == -1)
            e.Cancel = true;

        if (!IsPostBack)
        {
            e.Cancel = true;//si es la primera vez que entro, no dejo que filtre
        }
    }
    protected void btnVerTareas_Click(object sender, EventArgs e)
    {
        //obtngo el usuario
        string _usuario = UsuariosDropDownlist.SelectedItem.Value.ToString();

        //obtengo la contraseña
        string _contrasena = ContrasenaText.Text;

        if (ONEmpleado.ValidarCredenciales(_usuario, _contrasena) == false)
        {
            lblMensaje.Visible = true;
            return;
        }
        FormsAuthentication.RedirectFromLoginPage(_usuario, false);

        //lblMensaje.Visible = false;
        //gvTareas.DataBind();
    }
    protected void gvTareas_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        string s = e.Parameters[1].ToString();
    }
    protected void gvTareas_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
    {

    }
    protected void gvTareas_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
    {
        
    }
    protected void btnIniciar_Click(object sender, EventArgs e)
    {
        int _tareaId = int.Parse(((DevExpress.Web.ASPxEditors.ASPxButton)sender).CommandArgument);
        
        ONTareaLineaDeTiempo _tareaLT = ONTareaLineaDeTiempo.CrearTareaLineaDeTiempo(_tareaId);
        _tareaLT.IniciarTarea(DateTime.Now); //se almacena todo automaticamente
        gvTareas.DataBind();

    }
    protected void btnPausar_Click(object sender, EventArgs e)
    {
        int _tareaId = int.Parse(((DevExpress.Web.ASPxEditors.ASPxButton)sender).CommandArgument);
        int _visibleIndex = gvTareas.FindVisibleIndexByKeyValue(_tareaId);

        ONTareaLineaDeTiempo _tareaLT = ONTareaLineaDeTiempo.CrearTareaLineaDeTiempo(_tareaId);

        string _motivo = ((DevExpress.Web.ASPxEditors.ASPxComboBox)gvTareas.FindRowCellTemplateControl(_visibleIndex, null, "ddlMotivos")).Text;
        
        _tareaLT.PausarTarea(_motivo,DateTime.Now); //se almacena todo automaticamente
        
        gvTareas.DataBind();
    }
    protected void btnFinalizar_Click(object sender, EventArgs e)
    {
        int _tareaId = int.Parse(((DevExpress.Web.ASPxEditors.ASPxButton)sender).CommandArgument);
        int _visibleIndex = gvTareas.FindVisibleIndexByKeyValue(_tareaId);

        ONTareaLineaDeTiempo _tareaLT = ONTareaLineaDeTiempo.CrearTareaLineaDeTiempo(_tareaId);

        _tareaLT.FinalizarTarea("Finalización de tarea", DateTime.Now); //se almacena todo automaticamente

        gvTareas.DataBind();
    }
    protected void btnCerrar_Click(object sender, EventArgs e)
    {
        Response.Redirect("EjecucionTareas.aspx");
    }
}
